package comm;

import comm.SocketUtil.*;
import javafx.concurrent.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;

@SpringBootApplication(scanBasePackages = {"comm"}, exclude = {DataSourceAutoConfiguration.class})
@EnableTransactionManagement
public class ServerMain extends SpringBootServletInitializer implements ApplicationRunner {

    @Autowired
    ServerSocketBase serverSocketBase;

    public static void main(String[] args) {
        SpringApplication.run(ServerMain.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(ServerMain.class);
    }

    @Override
    public void run(ApplicationArguments args) {
        serverSocketBase.ServerSocket();
    }
}